var storejson = new Array();
function initPage() {
    $.ajax({
        url: "./goPCDD/initPage", //请求的url地址
        xhrFields: {
            withCredentials: true
        },
        async:false,
        dataType: "json", //返回格式为json
        type: "GET", //请求方式
        processData: false, //对表单data数据是否进行序列化
        contentType: false, //dataType设置你收到服务器数据的格式
        headers: {
            'Content-Type': 'application/json'
        },
        beforeSend: function() {
            //请求前的处理
        },
        success: function(data) {
            if(data.status==0){
                // top.location.href = "../../login.html";
                window.location.href="./login.html";
            }else{
                var json = JSON.parse(data.data)
                var tempstorejson = json.data;
                for(var i=0;i<tempstorejson.length;i++){
                    var temp = {
                        value: tempstorejson[i].Post,
                        label: tempstorejson[i].Post
                    };
                    storejson.push(temp)
                }
            }
        },
        complete: function() {
            //请求完成的处理
        },
        error: function() {}
    });
}

var vm = new Vue({
    el:"#app",
    data(){
        return {
            formItem: {
                UserNo: '',
                Store: '',
                Bm:'',
                Name:'',
                DriveYears:'',
                StartHaveLicenseDate:'',
                CanUseCarType:'',
                Status:'',
                Sex:'',
                Birthday:'',
                LicenseUntil:'',
                CardNo:'',
                PhoneNo:'',
                RecordNo:'',
                EditMan:'',
                EditNo:'',
                EditDate:'',
            },
            //中心店面下拉
            StoreJson: storejson,

            input2:'',
            model1: '',
            model1:false,
            options3: {
                disabledDate (date) {
                    return date;
                }
            },
        }
    },
    created: function () {
        initPage();
    },
    methods:{
        tansuccess (nodesc) {
            this.$Notice.success({
                title: 'Notification title',
                desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
            });
        },
        //手机号验证
        isPoneAvailable(str) {
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        //固定电话验证
        isFixPoneAvailable(str) {
            var myreg=/^0\d{2,3}-\d{7,8}(-\d{1,6})?$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        //身份证号验证
        isCardNoAvailable(str) {
            var myreg=/^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        saveManInfo() {
            var self = this;
            var jsondata = self.formItem;
            var EditNameStr = parent.$("#uname1").text();
            var EditIDStr = parent.$("#userno1").text();
            jsondata.EditMan = EditNameStr;
            jsondata.EditNo = EditIDStr;

            //校验开始
            if(jsondata.UserNo==''||jsondata.UserNo==null){
                toastr.warning("请输入员工编号");
                return false;
            }
            if(jsondata.Store==''||jsondata.Store==null){
                toastr.warning("请选择中心店面");
                return false;
            }
            if(jsondata.Bm==''||jsondata.Bm==null){
                toastr.warning("请输入部门");
                return false;
            }
            if(jsondata.Name==''||jsondata.Name==null){
                toastr.warning("请输入姓名");
                return false;
            }
            if(jsondata.Sex==''||jsondata.Sex==null){
                toastr.warning("请输入性别");
                return false;
            }
            if(jsondata.Birthday==''||jsondata.Birthday==null){
                toastr.warning("请输入生日");
                return false;
            }
            var tempBirthday = new Date(jsondata.Birthday);
            jsondata.Birthday = tempBirthday.toLocaleDateString();

            /*if(jsondata.CardNo==''||jsondata.CardNo==null){
                toastr.warning("请输入身份证号");
                return false;
            }
            if(!this.isCardNoAvailable(jsondata.CardNo)){
                toastr.warning("请输入正确格式的身份证号");
                return false;
            }*/
            if(jsondata.PhoneNo==''||jsondata.PhoneNo==null){
                toastr.warning("请输入手机号");
                return false;
            }
            if(!this.isPoneAvailable(jsondata.PhoneNo)){
                toastr.warning("请输入正确格式的手机号");
                return false;
            }
            if(jsondata.DriveYears==''||jsondata.DriveYears==null){
                toastr.warning("请输入驾龄");
                return false;
            }
            var DriverYears = jsondata.DriveYears;
            if(isNaN(DriverYears)){
                toastr.warning("驾龄请输入数字");
                return false;
            }

            if(jsondata.CanUseCarType==''||jsondata.CanUseCarType==null){
                toastr.warning("请输入准假车型");
                return false;
            }

            if(jsondata.Status==''||jsondata.Status==null){
                toastr.warning("请选择出车状态");
                return false;
            }

            if(jsondata.RecordNo==''||jsondata.RecordNo==null){
                toastr.warning("请输入档案编号");
                return false;
            }

            if(jsondata.StartHaveLicenseDate==''||jsondata.StartHaveLicenseDate==null){
                toastr.warning("请选择初次领证日期");
                return false;
            }
            var tempStartHaveLicenseDate = new Date(jsondata.StartHaveLicenseDate);
            jsondata.StartHaveLicenseDate = tempStartHaveLicenseDate.toLocaleDateString();

            if(jsondata.LicenseUntil==''||jsondata.LicenseUntil==null){
                toastr.warning("请选择驾驶证有效期至");
                return false;
            }
            var tempLicenseUntil = new Date(jsondata.LicenseUntil);
            jsondata.LicenseUntil = tempLicenseUntil.toLocaleDateString();

            //校验结束
            var data_json = JSON.stringify(jsondata)
            $.ajax({
                url: "./goPCDD/saveMan", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    if(data.status=='1'){
                        toastr.success('保存成功');
                        self.formItem.UserNo = '';
                        self.formItem.Store = '';
                        self.formItem.Bm = '';
                        self.formItem.Name = '';
                        self.formItem.DriveYears = '';
                        self.formItem.StartHaveLicenseDate = '';
                        self.formItem.CanUseCarType = '';
                        self.formItem.Sex = '';
                        self.formItem.Birthday = '';
                        self.formItem.LicenseUntil = '';
                        self.formItem.CardNo = '';
                        self.formItem.PhoneNo = '';
                        self.formItem.RecordNo = '';
                        self.formItem.EditMan = '';
                        self.formItem.EditNo = '';
                        self.formItem.EditDate = '';
                    }else{
                        toastr.error('保存失败，请重新录入');
                    }
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });

        },
        //取消
        goBack(){
            window.location.href = "./man_search.html";
        }
    }
})